package models

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"house/appconfig"
)

var DB *gorm.DB
var err error

func MysqlLink() {
	Dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8&parseTime=True&loc=Local", appconfig.AppConfig.Mysql.User, appconfig.AppConfig.Mysql.Password, appconfig.AppConfig.Mysql.Host, appconfig.AppConfig.Mysql.Port, appconfig.AppConfig.Mysql.Database)
	DB, err = gorm.Open(mysql.Open(Dsn))
	if err != nil {
		panic(err)
	}
	fmt.Println("数据库连接成功")
}
